<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>    
        //  function BitMap(size){
        //     var bit_arr = new Array(size);

        //     for(var i=0; i<bit_arr.length;i++){
        //         bit_arr[i] = 0;
        //     }

        //     this.addMember=function(member){
        //         var arr_index = Math.floor(member/32);
        //         var bit_index = member%32;
        //         bit_arr[arr_index] =  bit_arr[arr_index] | 1<<bit_index;
        //     }

        //     this.isExist=function(member){
        //         var arr_index = Math.floor(member/32);
        //         var bit_index = member%32;
        //         var val = bit_arr[arr_index] & 1<<bit_index;
        //         if(val != 0){
        //             return true;
        //         }
        //         return false;
        //     }
        //  }

        //  var arr=[0,6,88,7,73,34,10,99,22];
        //  var sort_arr=[];
        //  var bit_map=new BitMap();
        //  for(var i=0; i<arr.length;i++){
        //     bit_map.addMember(arr[i]);
        //  }

        //  for(var i=0;i<100;i++){
        //      if(bit_map.isExist(i)){
        //         sort_arr.push(i);
        //      }
        //  }
        //  console.log(sort_arr)

         
        //  var arr1=[1,4,6,8,9,10,15];
        //  var arr2=[6,14,9,2,0,7];
        //  var arr=[];
        //  var bit_map=new BitMap();
        //  for(var i=0;i<arr1.length;i++){
        //      bit_map.addMember(arr1[i]);
        //  }
        //  for(var i=0;i<arr2.length;i++){
        //     if(bit_map.isExist(arr2[i])){
        //         arr.push(arr2[i]);
        //     }
        //  }
        //  console.log(arr)

         //存入负数的BitMap
         function BitMap(size){
            var bit_arr_just = new Array(Math.floor(size/2));
            var bit_arr_negative = new Array(Math.floor(size/2));

            for(var i=0; i<bit_arr_just.length;i++){
                bit_arr_just[i] = 0;
                bit_arr_negative[i] = 0;
            }

            this.addMember=function(member){
                var arr_index = Math.floor(member/32);
                var bit_index = member%32;
                if(member<0){
                    bit_arr_negative[Math.abs(arr_index)] =  bit_arr_negative[Math.abs(arr_index)] | 1<<Math.abs(bit_index);
                }else{
                    bit_arr_just[arr_index] =  bit_arr_just[arr_index] | 1<<bit_index;
                }
            }

            this.isExist=function(member){
                var arr_index = Math.floor(member/32);
                var bit_index = member%32;
                if(member<0){
                    var val =  bit_arr_negative[Math.abs(arr_index)] & 1<<Math.abs(bit_index);
                }else{
                    var val = bit_arr_just[arr_index] & 1<<bit_index;
                } 
                if(val != 0){
                    return true;
                }
                return false;
            }
         }
    </script>
</body>
</html>